import {connect} from 'react-redux';
import TodoList from '../compments/todo_list';
import {FILTER_SHOW_COMPLETED,FILTER_SHOW_ACTIVE,FILTER_SHOW_ALL} from '../actions';

const getVisibleTools = (todos,filter)=>{
    switch(filter){
        case FILTER_SHOW_COMPLETED:
            return todos.filter(t=>t.completed);
        case FILTER_SHOW_ACTIVE:
            return todos.filter(t=>!t.completed);
        case FILTER_SHOW_ALL:
        default:
            return todos;
    }
}

const mapStateToProps = (state)=>{
    return {
        todos:getVisibleTools(state.todos,state.visibilityFilter),
        completed:state.completed
    }
}

const mapDispatchToProps = (dispatch)=>{
    return {
        dispatch
    }
}
//将显示组件与属性赋值
let TodoListContainer = connect(mapStateToProps,mapDispatchToProps)(TodoList);
export default  TodoListContainer;

//报错
// export default TodoListContainer = connect(mapStateToProps)(TodoList);